//
//  CYSelectCardCell.m
//  cyjf
//
//  Created by tauCross on 2017/5/15.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYSelectCardCell.h"

#import <UIImageView+WebCache.h>



@implementation CYSelectCardCellObject

@end



@interface CYSelectCardCell ()

@property(nonatomic, strong)UIImageView *bankIconImageView;
@property(nonatomic, strong)UILabel *cardInfoLabel;
@property(nonatomic, strong)UILabel *onceLimitLabel;
@property(nonatomic, strong)UILabel *totalLimitLabel;
@property(nonatomic, strong)UIImageView *bottomLine;

@end


@implementation CYSelectCardCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.bankIconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 33, 33)];
        [self.contentView addSubview:self.bankIconImageView];
        
        self.cardInfoLabel = [[UILabel alloc] init];
        self.cardInfoLabel.textColor = HEXCOLOR(@"444444");
        self.cardInfoLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:self.cardInfoLabel];
        
        self.onceLimitLabel = [[UILabel alloc] init];
        self.onceLimitLabel.textColor = HEXCOLOR(@"999999");
        self.onceLimitLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.onceLimitLabel];
        
        self.totalLimitLabel = [[UILabel alloc] init];
        self.totalLimitLabel.textColor = HEXCOLOR(@"999999");
        self.totalLimitLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.totalLimitLabel];
        
        self.bottomLine = [[UIImageView alloc] initWithImage:[UIImage imageWithColor:HEXCOLOR(@"ECECEC") size:CGSizeMake(1, 1)]];
        [self.contentView addSubview:self.bottomLine];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 65;
}

- (BOOL)shouldUpdateCellWithObject:(CYSelectCardCellObject *)object
{
    [self.bankIconImageView sd_setImageWithURL:object.bankIcon.tc_url placeholderImage:APP_SQUARE_PLACEHOLDER];
    
    self.cardInfoLabel.text = [NSString stringWithFormat:@"%@（%@）", object.bankName, object.cardNumber];
    
    self.onceLimitLabel.hidden = !object.hasLimit;
    self.onceLimitLabel.text = object.onceLimit;
    
    self.totalLimitLabel.hidden = !object.hasLimit;
    self.totalLimitLabel.text = object.totalLimit;
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.bankIconImageView.left = 20;
    self.bankIconImageView.centerY = self.contentView.height / 2;
    
    [self.cardInfoLabel sizeToFit];
    self.cardInfoLabel.left = 63;
    self.cardInfoLabel.centerY = self.onceLimitLabel.hidden ? self.contentView.height / 2 : 23;
    
    [self.onceLimitLabel sizeToFit];
    self.onceLimitLabel.left = 63;
    self.onceLimitLabel.centerY = 44;
    
    [self.totalLimitLabel sizeToFit];
    self.totalLimitLabel.left = self.onceLimitLabel.right + 13;
    self.totalLimitLabel.centerY = self.onceLimitLabel.centerY;
    
    self.bottomLine.width = self.contentView.width - 20;
    self.bottomLine.height = 1 / SCREEN_SCALE;
    self.bottomLine.right = self.contentView.width;
    self.bottomLine.bottom = self.contentView.height;
}

@end
